package com.blog.controller.forntend;


import com.blog.entity.Cert;
import com.blog.service.CertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mars123
 * @since 2019-07-02
 */
@Controller
@RequestMapping("/frontend/cert")
public class CertController {

    @Autowired
    private CertService certService;

//    @RequestMapping("/index")
//    public String index() {
//        return "redirect:/frontend/product/index";
//    }

    @RequestMapping("/create")
    public String create(HttpSession session, @ModelAttribute("cert") Cert cert, HttpServletRequest request) {

        if (request.getMethod().equals("POST")) {
            certService.addProduct(session, cert);
        }
        return "redirect:/frontend/product/index";
    }


    @RequestMapping("/delete")
    public String delete(HttpSession session, Integer id) {
        certService.removeProduct(session, id);
        return "redirect:/frontend/product/index";
    }


}

